package top.maof.book.model;

import com.baomidou.mybatisplus.annotation.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
import java.io.Serializable;
import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName("user")
public class User implements Serializable {
    @TableId(type = IdType.AUTO)
    private Integer id;

    @NotBlank
    private String username;

    private String password;

    private String nickname;

    private String salt;

    @Email
    @NotBlank
    private String email;

    @Pattern(regexp = "^1(3|4|5|7|8)\\\\d{9}$", message = "手机号码格式错误")
    @NotBlank
    private String phoneNumber;

    private String img;

    public User(Integer id, String username, String password, String nickname, String salt,
                String email, String phoneNumber,
                String img, List<Role> roles) {
        this.id = id;
        this.username = username;
        this.password = password;
        this.nickname = nickname;
        this.salt = salt;
        this.email = email;
        this.phoneNumber = phoneNumber;
        this.img = img;
        this.roles = roles;
    }

    @TableField(fill = FieldFill.INSERT)
    private Long insertTime;

    @TableField(fill = FieldFill.INSERT_UPDATE)
    private Long updateTime;

    @TableField(exist = false)
    private List<Role> roles;
}
